package com.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

@Entity
@NamedQueries(
		{
			@NamedQuery(name = "Member.findMemberByNRIC", query = "select m from Member m where m.nric = :nric"),
			@NamedQuery(name = "Member.findMemberByStatusSuspend", query = "select m from Member m where m.active = :active and m.suspend = :suspend order by membershipExpiryDate"),
			@NamedQuery(name = "Member.advanceSearch", query = "select m from Member m where m.name like :name and m.nric like :nric and m.email like :email and m.mobileNo like :mobile and m.active = :terminate and m.suspend = :suspended and m.dob between :dobFrom and :dobTo and m.membershipExpiryDate between :expiryFrom and :expiryTo and m.membershipLastPaymentDate between :lastPaymentFrom and :lastPaymentTo"),
			@NamedQuery(name = "Member.membershipAutoComplete", query = "select m from Member m where m.name like :name and m.active = :active and m.suspend = :suspended")
		}
	)

public class Member implements Serializable{
	private static final long serialVersionUID = 1L;
	public static final String FIND_MEMBER_BY_NRIC = "Member.findMemberByNRIC";
	public static final String FIND_MEMBER_BY_STATUS_SUSPEND = "Member.findMemberByStatusSuspend";
	public static final String ADVANCE_SEARCH = "Member.advanceSearch";
	public static final String MEMBERSHIP_AUTOCOMPLETE = "Member.membershipAutoComplete";
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	private String name;
	@Column(unique = true)
	private String nric;
	private Date dob;
	private String address1;
	private String address2;
	private String address3;
	private String occupation;
	private String mobileNo;
	private String email;
	private String gender;
	
	@ManyToOne
	private Membership membership;
	private Date membershipLastPaymentDate;
	private Date membershipExpiryDate;
	
	
	private String emergencyName;
	private String emergencyContactNo;
	private String relationship;
	
	private Date createdDate;
	@ManyToOne
	@JoinColumn(name="createdBy")
	private User createdBy;
	
	private Date updatedDate;
	@ManyToOne
	@JoinColumn(name="updatedBy")	
	private User updatedBy;
	
	private boolean suspend;
	private boolean active;
	
	@ManyToMany
	private List<Medical> medicals;
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name.toUpperCase();
	}
	public String getNric() {
		return nric;
	}
	public void setNric(String nric) {
		this.nric = nric.toUpperCase();
	}
	public Date getDob() {
		return dob;
	}
	public void setDob(Date dob) {
		this.dob = dob;
	}
	public String getAddress1() {
		return address1;
	}
	public void setAddress1(String address1) {
		this.address1 = address1.toUpperCase();
	}
	public String getAddress2() {
		return address2;
	}
	public void setAddress2(String address2) {
		this.address2 = address2.toUpperCase();
	}
	public String getAddress3() {
		return address3;
	}
	public void setAddress3(String address3) {
		this.address3 = address3.toUpperCase();
	}
	public String getOccupation() {
		return occupation;
	}
	public void setOccupation(String occupation) {
		this.occupation = occupation.toUpperCase();
	}
	public String getMobileNo() {
		return mobileNo;
	}
	public void setMobileNo(String mobileNo) {
		this.mobileNo = mobileNo;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email.toUpperCase();
	}
	public String getEmergencyName() {
		return emergencyName;
	}
	public void setEmergencyName(String emergencyName) {
		this.emergencyName = emergencyName.toUpperCase();
	}
	public String getEmergencyContactNo() {
		return emergencyContactNo;
	}
	public void setEmergencyContactNo(String emergencyContactNo) {
		this.emergencyContactNo = emergencyContactNo.toUpperCase();
	}
	public String getRelationship() {
		return relationship;
	}
	public void setRelationship(String relationship) {
		this.relationship = relationship.toUpperCase();
	}
	public List<Medical> getMedicals() {
		return medicals;
	}
	public void setMedicals(List<Medical> medicals) {
		this.medicals = medicals;
	}
	public boolean isSuspend() {
		return suspend;
	}
	public void setSuspend(boolean suspend) {
		this.suspend = suspend;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public Membership getMembership() {
		return membership;
	}
	public void setMembership(Membership membership) {
		this.membership = membership;
	}
	public Date getMembershipLastPaymentDate() {
		return membershipLastPaymentDate;
	}
	public void setMembershipLastPaymentDate(Date membershipLastPaymentDate) {
		this.membershipLastPaymentDate = membershipLastPaymentDate;
	}
	public Date getMembershipExpiryDate() {
		if(membershipExpiryDate == null){
			membershipExpiryDate = new Date();
		}
		return membershipExpiryDate;
	}
	public void setMembershipExpiryDate(Date membershipExpiryDate) {
		this.membershipExpiryDate = membershipExpiryDate;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public Date getCreatedDate() {
		return createdDate;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	public User getCreatedBy() {
		return createdBy;
	}
	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}
	public Date getUpdatedDate() {
		return updatedDate;
	}
	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
	public User getUpdatedBy() {
		return updatedBy;
	}
	public void setUpdatedBy(User updatedBy) {
		this.updatedBy = updatedBy;
	}
	
	
	
	
}
